import React from 'react';
import {
    Table,
    Badge,
    Tooltip
} from 'antd';
import axios from 'axios';
import intercept from '../../../utils/intercept';
import {config} from 'utils';
import moment from 'moment'
import './OrderInfo.less'

//订单详情组件
export default class OrderList extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            loading: true,
            data: []
        };
    }

    componentDidMount() {
        this.getOrderdetail();
    };
    getOrderdetail() {
        const token = sessionStorage.getItem("token");
        // this.setState({loading: true});
        const url = `${config.api}CustomService/GetOrderDetail?orderCode=${this.props.ordercode}`;
        axios
            .get(url,{headers:{Authorization:'Bearer ' + token}})
            .then((data) => {
                //console.log(data);
                this.setState({loading: false, data: data.data.pageList.collections});
            })
            .catch( err => {
                intercept;
            })
    };
    render() {
        const statusstr = ['待支付','已支付','已取消','已打印','客服申请退款','客服申请退款成功','超时支付申请退款','超时支付退款成功','用户申请退款','退款成功'];
        const column = [
            {
                title: '姓名',
                dataIndex: 'name',
                width: 150
            }, {
                title: '身份证',
                dataIndex: 'cardid',
                width: 150
            }, {
                title: '电话',
                dataIndex: 'tel',
                width: 150
            }
            , {
                title: '状态',
                dataIndex: 'status',
                width: 150,
                render:(text, record) => {
                    return(
                      <span>{statusstr[record.status]}</span>
                    )
                }
            }
            , {
                title: '票号',
                dataIndex: 'ticketNum',
                width: 150
            }
            , {
                title: '打印时间',
                dataIndex: 'printTime',
                width: 150,
                render:(text, record) => {
                    return(
                      record.isStationStatus?
                      <Tooltip placement="top" title={'带红点的为从车站获取的状态'}><Badge dot={true}><span>{record.printTime == null ? "未打印": new moment(record.printTime).format('YYYY-MM-DD hh:mm')}</span></Badge></Tooltip>
                      :
                      <span>{record.printTime == null ? "未打印": new moment(record.printTime).format('YYYY-MM-DD hh:mm')}</span>
                    )
                }
            }
        ];
        return (<Table
            columns={column}
            rowClassName={() => {return 'childtable'}}
            dataSource={this.state.data}
            bordered={true}
            pagination={false}
            size="small"/>);
    }
}
